#import "music.h"
#import "SimpleAudioEngine.h"

void MusicLoad()
{
	if (nil != g_SceneMenu)
	{
		[[SimpleAudioEngine sharedEngine] preloadBackgroundMusic:@"BGM_Main.mp3"];
		return;
	}
	if (nil != g_SceneMenu)
	{
		switch (g_ChapterMissionID)
		{
		case 5:
		case 10:
		case 15:
			[[SimpleAudioEngine sharedEngine] preloadBackgroundMusic:@"BGM_BossBg1.mp3"];
			[[SimpleAudioEngine sharedEngine] preloadBackgroundMusic:@"BGM_BossBg2.mp3"];
			[[SimpleAudioEngine sharedEngine] preloadBackgroundMusic:@"BGM_BossBg3.mp3"];
			break;
		default:
			[[SimpleAudioEngine sharedEngine] preloadBackgroundMusic:@"BGM_battle.mp3"];
		}
		[[SimpleAudioEngine sharedEngine] preloadBackgroundMusic:@"BGM_BattleWin.mp3"];
		[[SimpleAudioEngine sharedEngine] preloadBackgroundMusic:@"BGM_BattleFail.mp3"];
		return;
	}
	if (nil != g_SceneLibrary)
	{
		[[SimpleAudioEngine sharedEngine] preloadBackgroundMusic:@"BGM_LibraryBg.mp3"];
		[[SimpleAudioEngine sharedEngine] preloadBackgroundMusic:@"BGM_StaffBg.mp3"];
		return;
	}
}

void MusicPlayMain()
{
	if (g_OptionBgm)
	{
		[[SimpleAudioEngine sharedEngine] playBackgroundMusic:@"BGM_Main.mp3" loop:false];
	}
}

void MusicPlayGame()
{
	if (g_OptionBgm)
	{
		switch (g_ChapterMissionID)
		{
		case 5:
		case 10:
		case 15:
			break;

		default:
			[[SimpleAudioEngine sharedEngine] playBackgroundMusic:@"BGM_battle.mp3" loop:false];
		}
	}
}

void MusicPlayGameBossStage1()
{
	if (g_OptionBgm)
	{
		[[SimpleAudioEngine sharedEngine] playBackgroundMusic:@"BGM_BossBg1.mp3" loop:true];
	}
}

void MusicPlayGameBossStage2()
{
	if (g_OptionBgm)
	{
		[[SimpleAudioEngine sharedEngine] playBackgroundMusic:@"BGM_BossBg3.mp3" loop:true];
	}
}

void MusicPlayGameBossStage3()
{
	if (g_OptionBgm)
	{
		[[SimpleAudioEngine sharedEngine] playBackgroundMusic:@"BGM_BossBg2.mp3" loop:true];
	}
}

void MusicPlayGameWin()
{
	if (g_OptionBgm)
	{
		[[SimpleAudioEngine sharedEngine] playBackgroundMusic:@"BGM_BattleWin.mp3" loop:false];
	}
}

void MusicPlayGameFail()
{
	if (g_OptionBgm)
	{
		[[SimpleAudioEngine sharedEngine] playBackgroundMusic:@"BGM_BattleFail.mp3" loop:false];
	}
}

void MusicPlayLibrary()
{
	if (g_OptionBgm)
	{
		[[SimpleAudioEngine sharedEngine] playBackgroundMusic:@"BGM_LibraryBg.mp3" loop:false];
	}
}

void MusicPlayLibraryCredits()
{
	if (g_OptionBgm)
	{
		[[SimpleAudioEngine sharedEngine] playBackgroundMusic:@"BGM_StaffBg.mp3" loop:false];
	}
}

void MusicStop()
{
	[[SimpleAudioEngine sharedEngine] stopBackgroundMusic];
}

void MusicPause()
{
	[[SimpleAudioEngine sharedEngine] pauseBackgroundMusic];
}

void MusicResume()
{
	[[SimpleAudioEngine sharedEngine] resumeBackgroundMusic];
}

void EffectButton()
{
	if (g_OptionSoundex)
	{
		[[SimpleAudioEngine sharedEngine] playEffect:@"SE_sndBtn.wav"];
	}
}

void EffectHiddenObject()
{
	if (g_OptionSoundex)
	{
		[[SimpleAudioEngine sharedEngine] playEffect:@"SE_bridge_up.wav"];
	}
}

void EffectBridgeUp()
{
	if (g_OptionSoundex)
	{
		[[SimpleAudioEngine sharedEngine] playEffect:@"SE_bridge_up.wav"];
	}
}

void EffectEnemyDie()
{
	if (g_OptionSoundex)
	{
		switch (rand() % 2)
		{
		case 0:
			[[SimpleAudioEngine sharedEngine] playEffect:@"SE_Dead_1.wav"]; break;
		case 1:
			[[SimpleAudioEngine sharedEngine] playEffect:@"SE_Dead_2.wav"]; break;
		default:
			;
		}
	}
}

void EffectBombExplosion()
{
	if (g_OptionSoundex)
	{
		switch (rand() % 2)
		{
		case 0:
			[[SimpleAudioEngine sharedEngine] playEffect:@"SE_explosion_01.wav"]; break;
		case 1:
			[[SimpleAudioEngine sharedEngine] playEffect:@"SE_explosion_01.wav"]; break;
		default:
			;
		}
	}
}

void EffectItemMake()
{
	if (g_OptionSoundex)
	{
		[[SimpleAudioEngine sharedEngine] playEffect:@"SE_ItemMake.mp3"];
	}
}

void EffectPlay(char const *File)
{
	[[SimpleAudioEngine sharedEngine] playEffect:[NSString stringWithUTF8String:File]];
}